public class Main {
    public static void main(String[] args) {
        String s = "Hello World";
        System.out.println(lengthOfLastWord(s));
    }
    public static int lengthOfLastWord(String s) {
        int count = 0;
        int i = s.length()-1;
        while (s.charAt(i) == ' ') {
            i--;
        }
        for (int j = i; j >= 0; j--) {
            if(s.charAt(j) == ' ') {
                break;
            }else {
                count++;
            }
        }
        return count;
    }
}
